package org.geektimes.projects.user.bean.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class MinLengthValidator implements ConstraintValidator<MinLength, CharSequence> {
    private long minValue;

    @Override
    public void initialize(MinLength minLength) {
        this.minValue = minLength.value();
    }

    @Override
    public boolean isValid(CharSequence value, ConstraintValidatorContext context) {
        if ( value == null ) {
            return true;
        }

        return value.length() > minValue;
    }
}
